<template>
  <div>
    <!-- 标题 -->
    <div class="header">
      <div class="header-box">
        <div class="header-l">
          <van-icon name="arrow-left" />
          <span @click="backTo">返回</span>
        </div>

        <h2 class="header-m" >确认订单</h2>
        <div></div>
      </div>
    </div>
    <div class="addressList" v-if="data.address"  @click="toAddress">
      <div v-if="data.address.is_default==1?true:false" class="l-txt">默认</div>
      <div class="r-txt">
        <span class="txt-t">{{ data.address.address }}</span>
        <span class="txt-b"
          >{{ data.address.name }}{{ data.address.mobile }}</span
        >
      </div>
    </div>

    <div class="goods" v-if="data.goodsList">
      <ul class="goodsList">
        <li class="goods-item" v-for="item in data.goodsList">
          <img class="img" :src="item.list_pic_url" alt="" />
          <div class="r-txt">
            <div class="txt-l">
              <p>{{ item.goods_name }}</p>
              <p>{{ item.retail_price }}</p>
            </div>
            <p>X{{ item.number }}</p>
          </div>
        </li>
      </ul>
    </div>

    <div class="price" v-if="data.address">
      <div class="txt">
        <span class="txt-t">总价</span>
        <span class="txt-b">${{ data.allPrise }}</span>
      </div>

      <div class="txt">
        <span class="txt-t">运费</span>
        <span class="txt-b">包邮</span>
      </div>

      <div class="txt">
        <span class="txt-t">优惠券</span>
        <span class="txt-b">暂无</span>
      </div>
    </div>

    <div class="footer">
      <div class="footer-r">
        实付<span class="txt">${{ data.allPrise }}</span>
      <button >付款</button>
      </div>
     
    </div>
  </div>
</template>

<script>
import { detailAction } from "@/api/cart";
import { getListAction } from "@/api/user";
export default {
  name: "",
  data() {
    return {
      addressId: "",
      data: [],
      flag:false
    };
  },
 async created() {
    if(!this.$store.state.address){
      let a=await  getListAction({
      openId: localStorage.getItem("openId"),
    })
      console.log(a);
   
    }else{
      this.addressId=this.$store.state.address
    }
    let b=await detailAction({
      openId: localStorage.getItem("openId"),
      addressId: this.addressId,
    })
      this.data = b;
      console.log("12", b, this.data);
  
  },
  mounted() {
    
  },
  methods: {
    backTo() {
      this.$router.back();
      this.$store.state.address=''
    },
    toAddress(){
      this.$router.push('/user/address')
    }
  },
};
</script>

<style scoped lang="scss">
@import "./scss/index.scss";
</style>